import time

import allure
from selenium.webdriver.common.by import By

from po.page.base_page import BasePage
from po.utils.log_utils import logger


class ContactPage(BasePage):
    """通讯录界面"""
    _ADD_MEMBER_BTN = By.XPATH, '//*[text()="组织架构"]'
    _ADD_MEMBER = By.XPATH, '(//*[text()="添加成员"])[2]'
    _MEMBER_LIST_NAME = By.XPATH, '//*[text()="通讯录"]'
    _WAIT = By.CSS_SELECTOR, "#member_list>tr>td:nth-child(2)"

    @allure.step("进入添加成员页面")
    def goto_add_member(self):
        """
        进入添加成员页面
        :return:
        """
        self.wait_locate(*self._MEMBER_LIST_NAME)
        self.find_ele(*self._ADD_MEMBER_BTN).click()
        time.sleep(2)
        self.driver.find_element(*self._ADD_MEMBER).click()
        logger.info("进入添加成员页面")
        from po.page.add_member_page import AddMemberPage
        return AddMemberPage(self.driver)

    @allure.step("获取列表成员姓名列表")
    def get_user_info(self):
        """
        获取成员信息
        :return:
        """
        self.wait_locate(*self._MEMBER_LIST_NAME)
        self.wait_locate(*self._WAIT)
        member_list = self.find_eles(*self._WAIT)
        name_list = []
        for i in member_list:
            name_list.append(i.text)

        logger.info(f"获取到的成员列表为{name_list}")
        return name_list
